<!--
 * @Author: gao_m3
 * @Date: 2020-11-02 10:31:25
 * @LastEditors: chen_yt
 * @LastEditTime: 2022-07-12 14:24:46
 * @Descripttion: 
-->
<template>
  <div class="drawer-container">
    <file-server
      :file-server-config="fileServerConfig"
      :update-config="updateConfig"
    />
  </div>
</template>

<script>
import { deepClone } from '@/utils/util'
import Mix from '@/mixins/module'
import SaasMix from '@/saas/mixins'
import FileServer from './components/FileServer'
import { getServerConfig, setServerConfig } from '../api'

export default {
  name: 'Server',
  components: { FileServer },
  mixins: [Mix, SaasMix],
  data() {
    return {
      serverType: 'mailServerConfig',
      smsServerConfig: [],
      mailServerConfig: [],
      fileServerConfig: {},
      initData: {}
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    serverAdd() {},

    init() {
      getServerConfig()
        .then((res) => {
          if (res.status) {
            this.smsServerConfig = res.data.smsServerConfig
            this.mailServerConfig = res.data.mailServerConfig
            this.fileServerConfig = res.data.fileServerConfig
            this.initData = deepClone(res.data)
          }
        })
        .catch(() => {})
    },

    /**
     * @description: 更新服务器配置的回调
     */
    updateConfig(config, init) {
      let params = {
        ...this.initData,
        ...config
      }
      return setServerConfig(params)
        .then((res) => {
          if (!res.status) {
            this.init()
          }
          return res
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.drawer-container {
  width: 100%;
  min-width: 648px;
  height: 100%;
  overflow-y: auto;
  background-color: white !important;

  .item-container {
    width: 100%;
  }
}
</style>